from etgui import ShowURL
from tempfile import mktemp
from os import path
_cache={}
def expand_path(p):
	return path.expanduser(path.expandvars(p))
def join(*args):
	return reduce(path.join,args)

def GetHTMLFile(html):
	if _cache.has_key(html):
		return _cache[html]
	else:
		tmp=mktemp()
		file=open(tmp,'w')
		file.write(html)
		file.close()
		_cache[html]=tmp
		return tmp
def ShowHTML(html):
	ShowURL("file:%s"%GetHTMLFile(html))

def ShowDocu(relpath):
	p=join(GetSniffDir(),'doc','online',relpath)
	#print p
	ShowURL("file:%s"%p)
 
def escape(s):
	"""Replace special characters '&', '<' and '>' by SGML entities."""
	import regsub
	s = regsub.gsub("&", "&amp;", s)	# Must be done first!
	s = regsub.gsub("<", "&lt;", s)
	s = regsub.gsub(">", "&gt;", s)
	return s
